﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class RenderTextureSizer : MonoBehaviour
{
    public RenderTexture renderTexture;
    public RectTransform targetSize;

    void Update()
    {
        if (new Vector2(renderTexture.width, renderTexture.height) != targetSize.sizeDelta)
        {
            renderTexture.Release();
            renderTexture.width = Mathf.Abs(Mathf.RoundToInt(targetSize.sizeDelta.x));
            renderTexture.height = Mathf.Abs(Mathf.RoundToInt(targetSize.sizeDelta.y));
            renderTexture.Create();
            //TunerCamera.rect = new Rect(0, 0, 1, 1);
        }
    }

    private void OnApplicationQuit()
    {
        renderTexture.Release();
        renderTexture.width = 2048;
        renderTexture.height = 1080;
        renderTexture.Create();
    }
}
